package com.example.sp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.sp.entity.StuZs;
import com.example.sp.service.StuzsService;
import com.example.sp.utils.Res;
import com.example.sp.utils.Result;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/zs")
@AllArgsConstructor
@Slf4j
public class StuzsController {
    private final StuzsService stuzsService;
    @RequestMapping("all")
    public Result select1(){
        return Res.ok(stuzsService.listMaps(new QueryWrapper<StuZs>().select("*").groupBy("city")));

    }

    /**
     * 新增数据
     * @param eneity
     * @return
     */
    @PostMapping
    public Result insert(@RequestBody StuZs eneity){
        stuzsService.save(eneity);
        return Res.ok("插入成功！");
    }

    /**
     * 修改数据
     * @param eneity
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody StuZs eneity){
        stuzsService.updateById(eneity);
        return Res.ok("修改成功！");
    }

    /**
     * 删除数据
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Long id){
        stuzsService.removeById(id);
        return Res.ok("删除成功！");
    }

}
